<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#adminGetSalesVolumeList").click(function() {
		$.ajax({
			type:"post",
			url:"adminGetSalesVolumeList.do",
			dataType:"json",
			success:function(jsonData){
				alert("판매량통계정렬입니다.");
				$("#productView tr").remove();
				var tbody="";
				$.each(jsonData,function(index,str){
					tbody+="<tr>";
					tbody+="<td>"+str.sellerId+"</td><td>"+str.productName+"</td>";
					tbody+="<td>"+str.productPrice+"</td><td>"+str.productMaker+"</td>";
					tbody+="<td>"+str.productDate+"</td><td>"+str.productCategory+"</td>";
					tbody+="<td>"+str.starRating/20+"</td><td>"+str.productAvailable+"</td>";
					tbody+="<td>"+str.inventoryVO.inventoryAmount+"</td><td bgcolor=yellow>"+str.inventoryVO.salesVolume+"</td>";
					tbody+="<td>"+str.inventoryVO.salesVolume*str.productPrice+"</td>";
					tbody+="</tr>";
				});   //each
				$("#productView").html(tbody);
			}
		});
	});
	
	$("#adminGetSalesProfitList").click(function() {
		$.ajax({
			type:"post",
			url:"adminGetSalesProfitList.do",
			dataType:"json",
			success:function(jsonData){
				alert("판매수익통계정렬입니다.");
				$("#productView tr").remove();
				var tbody="";
				$.each(jsonData,function(index,str){
					tbody+="<tr>";
					tbody+="<td>"+str.sellerId+"</td><td>"+str.productName+"</td>";
					tbody+="<td>"+str.productPrice+"</td><td>"+str.productMaker+"</td>";
					tbody+="<td>"+str.productDate+"</td><td>"+str.productCategory+"</td>";
					tbody+="<td>"+str.starRating/20+"</td><td>"+str.productAvailable+"</td>";
					tbody+="<td>"+str.inventoryVO.inventoryAmount+"</td><td>"+str.inventoryVO.salesVolume+"</td>";
					tbody+="<td bgcolor=yellow>"+str.inventoryVO.salesVolume*str.productPrice+"</td>";
					tbody+="</tr>";
				});   //each
				$("#productView").html(tbody);
			}
		});
	});
	
	$("#findProductName").click(function() {
		$.ajax({
			type:"post",
			url:"findProductName.do",
			data:"productName="+$("#productName").val(),
			dataType:"json",
			success:function(jsonData){
				alert("상품 검색 결과입니다.");
				$("#productView tr").remove();
				var tbody="";
				$.each(jsonData,function(index,str){
					tbody+="<tr>";
					tbody+="<td>"+str.sellerId+"</td><td bgcolor=yellow>"+str.productName+"</td>";
					tbody+="<td>"+str.productPrice+"</td><td>"+str.productMaker+"</td>";
					tbody+="<td>"+str.productDate+"</td><td>"+str.productCategory+"</td>";
					tbody+="<td>"+str.starRating/20+"</td><td>"+str.productAvailable+"</td>";
					tbody+="<td>"+str.inventoryVO.inventoryAmount+"</td><td>"+str.inventoryVO.salesVolume+"</td>";
					tbody+="<td>"+str.inventoryVO.salesVolume*str.productPrice+"</td>";
					tbody+="</tr>";
				});   //each
				$("#productView").html(tbody);
			}
		});
	});
});
</script>
</head>
<body>
<h3>전체 상품 통계</h3>
<input type="button" id="adminGetSalesVolumeList" value="판매량통계정렬">
<input type="button" id="adminGetSalesProfitList" value="판매수익통계정렬">
상품이름: <input type="text" id="productName"><input type="button" id="findProductName" value="검색"><br><Br>
<table border="1" cellpadding="5">
<thead>
	<tr>
		<th>판매자아이디</th><th>상품이름</th><th>상품가격</th>	
		<th>제조사</th><th>상품등록일</th><th>상품카테고리</th>
		<th>별점</th><th>상품판매가능여부</th>	
		<th>재고량</th><th>판매량</th><th>판매수익</th>
	</tr>
</thead>
<tbody align="center" id="productView">
<c:forEach items="${requestScope.list }" var="li">
	<tr>
		<td>${li.sellerId }</td><td>${li.productName }</td><td>${li.productPrice }</td>	
		<td>${li.productMaker }</td><td>${li.productDate }</td><td>${li.productCategory }</td>
		<td>${li.starRating/20 }</td><td>${li.productAvailable }</td><td>${li.inventoryVO.inventoryAmount }</td>
		<td>${li.inventoryVO.salesVolume }</td><td>${li.inventoryVO.salesVolume*li.productPrice}</td>
	</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>